package com.big.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.big.app.dao.ShoppingDao;
import com.big.app.entity.Shopping;
import com.big.app.service.intf.ShoppingService;
import com.big.app.vo1.R;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ShoppingImpl implements ShoppingService {

    @Resource
    private ShoppingDao dao;
    @Override
    public R all(Shopping shopping) {
        String shoppinguser = shopping.getShoppinguser();
        return new R(200,"ok",dao.selectList(new QueryWrapper<Shopping>().eq("shoppinguser",shoppinguser)));
    }

    @Override
    public R update(Shopping shopping) {
        Integer shoppingId = shopping.getId();
        Shopping shopper = dao.selectOne(new QueryWrapper<Shopping>().eq("id", shoppingId));

        Integer shoppingcount = shopper.getShoppingcount();

        Integer shoppingcount1 = shopping.getShoppingcount();
        Integer count = shoppingcount-shoppingcount1;

        shopping.setShoppingcount(count);


        return new R(200,"ok",dao.updateById(shopping));
    }
}
